package com.wyx;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GroupExample {
    public static void main(String[] args) {
        String text = "The number is 1234.";
        Pattern pattern = Pattern.compile("number is (\\d+).");
        Matcher matcher = pattern.matcher(text);

        if (matcher.find()) {
            System.out.println("Group 0: " + matcher.group(0)); // 输出: number is 1234.
            System.out.println("Group 1: " + matcher.group(1)); // 输出: 1234
            System.out.println("Group 1: " + matcher.group(2)); // 输出: 1234
        }
    }
}
